package cn.itcast.mapper;

import cn.itcast.pojo.Clazz;
import cn.itcast.pojo.ClazzById;
import cn.itcast.pojo.ClazzGroup;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface ClazzMapper {

    @Select("select * from clazz")
    List<Clazz> findAllClazz();

    List<Clazz> findByColClazz(
            @Param("name") String name,
            @Param("begin") LocalDate begin,
            @Param("end") LocalDate end);

    @Delete("delete from clazz where id=#{id}")
    int deleteById(Integer id);

    @Insert("insert into clazz(name,room,begin_date,end_date,master_id,subject,create_time,update_time) values(#{name},#{room},#{beginDate},#{endDate},#{masterId},#{subject},#{createTime},#{updateTime})")
    int addClazz(Clazz clazz);

    @Select("select * from clazz where id=#{id}")
    ClazzById findById(Integer id);

    //未涉及多表直接使用keyvalue方式
    @Update("update clazz set name=#{name},room=#{room},begin_date=#{beginDate},end_date=#{endDate},master_id=#{masterId},subject=#{subject},update_time=#{updateTime} where id=#{id}")
    int updateClazz(Clazz clazz);

    List<ClazzGroup> studentCountData();
}
